package com.kobe.algorithm.leetcode.case6;

/**
 * @author ：caopengfei
 * @date ：2021/2/23
 */
public class Solution {

    /**
     * rowNumber N
     *
     * 0，4，8，12
     * 第一行的数字等于  2n-2
     * 第二行的1，3，5，7，9
     * 第三行是
     * 0
     * 1
     *
     *
     */
    public String convert(String s, int numRows) {
        if(s == null || s.length() ==0 || s.length()<numRows){
            return s;
        }
        char [] chars = s.toCharArray();
        char[][] charMap = new char[numRows][numRows];
        int rows = 0;
        int flag = 1;
        for (int i = 0;i< chars.length;i++){
            int x = rows;

            int y = i/numRows;
            charMap[y][x] = chars[i];
        }
        StringBuilder stringBuilder = new StringBuilder("");
        for (int i = 0;i<numRows;i++){
            for (int j = 0;j<numRows;j++){
                if(charMap[i][j] != 0){
                    stringBuilder.append(charMap[i][j]);
                }
            }
        }
        return stringBuilder.toString();
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.convert("PAYPALISHIRING", 4));
    }
}
